package com.hs.sfzy.mapper;

import com.hs.sfzy.entity.Course;
import com.hs.sfzy.entity.Question;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface QuestionMapper {


    List<Question> selectAll(String title);

    List<Question> selectAllForWx(Question question);

    int save(Question question);

    @Delete("delete from question where id = #{id}")
    int deleteById(Integer id);

    int update(Question question);

    @Select("select id , title from question")
    List<Question> findAllIDAndTitle();

    @Update("update question set replyCount = (select count(0) from reply where question_id = question.id) where question.id = #{id}")
    int updateReplyCount(Long id);

    @Update("update question set lastReplyTime = (select createTime " +
            "from reply where question_id = question.id " +
            "order by createTime desc limit 1) where question.id = #{id}")
    int updatelastReplyTime(Long id);
}
